home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / FunSnake / FunSnake.jar / FunSnake.class (.txt) next >
Encoding:
Java Class File  |  2002-05-20  |  2.7 KB  |  94 lines

  1. import javax.microedition.lcdui.Command;
  2. import javax.microedition.lcdui.CommandListener;
  3. import javax.microedition.lcdui.Display;
  4. import javax.microedition.lcdui.Displayable;
  5. import javax.microedition.lcdui.Form;
  6. import javax.microedition.lcdui.TextField;
  7. import javax.microedition.midlet.MIDlet;
  8. import javax.microedition.midlet.MIDletStateChangeException;
  9.  
  10. public class FunSnake extends MIDlet implements CommandListener {
  11.    private Command exitCommand = new Command("Exit", 7, 2);
  12.    private Command newGameCommand = new Command("New", 4, 2);
  13.    private Command returnCommand = new Command("Return", 4, 2);
  14.    private Display display = Display.getDisplay(this);
  15.    private FunSnakeCanvas screen;
  16.    private Form form = new Form("Bad Snake");
  17.    private TextField speed = new TextField("Speed: 0-9", "4", 1, 2);
  18.    private TextField level = new TextField("Level: 0-5", "0", 1, 2);
  19.    private TextField size = new TextField("Size: 2-5", "3", 1, 2);
  20.  
  21.    public FunSnake() {
  22.       this.form.append(this.speed);
  23.       this.form.append(this.level);
  24.       this.form.append(this.size);
  25.       this.form.addCommand(this.exitCommand);
  26.       this.form.addCommand(this.newGameCommand);
  27.       this.form.setCommandListener(this);
  28.    }
  29.  
  30.    public void startApp() throws MIDletStateChangeException {
  31.       this.display.setCurrent(this.form);
  32.    }
  33.  
  34.    public void pauseApp() {
  35.    }
  36.  
  37.    public void destroyApp(boolean var1) {
  38.    }
  39.  
  40.    public void commandAction(Command var1, Displayable var2) {
  41.       if (var1 == this.exitCommand) {
  42.          this.destroyApp(false);
  43.          ((MIDlet)this).notifyDestroyed();
  44.       } else if (var1 == this.newGameCommand) {
  45.          int var3 = Integer.parseInt(this.speed.getString());
  46.          int var4 = Integer.parseInt(this.level.getString());
  47.          int var5 = Integer.parseInt(this.size.getString());
  48.          short var6 = 300;
  49.          switch (var3) {
  50.             case 0:
  51.                var6 = 500;
  52.                break;
  53.             case 1:
  54.                var6 = 450;
  55.                break;
  56.             case 2:
  57.                var6 = 400;
  58.                break;
  59.             case 3:
  60.                var6 = 350;
  61.                break;
  62.             case 4:
  63.                var6 = 300;
  64.                break;
  65.             case 5:
  66.                var6 = 250;
  67.                break;
  68.             case 6:
  69.                var6 = 200;
  70.                break;
  71.             case 7:
  72.                var6 = 150;
  73.                break;
  74.             case 8:
  75.                var6 = 100;
  76.                break;
  77.             case 9:
  78.                var6 = 50;
  79.          }
  80.  
  81.          this.screen = new FunSnakeCanvas(var6, var4, var5);
  82.          this.screen.addCommand(this.exitCommand);
  83.          this.screen.addCommand(this.returnCommand);
  84.          this.screen.setCommandListener(this);
  85.          this.display.setCurrent(this.screen);
  86.       } else if (var1 == this.returnCommand) {
  87.          this.screen.snakeTimer.cancel();
  88.          this.screen = null;
  89.          this.display.setCurrent(this.form);
  90.       }
  91.  
  92.    }
  93. }
  94.